package com.hiwhitley.easy.day25;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by hiwhitley on 2016/10/21.
 */
public class SingleNumber_137 {
    public static int singleNumber(int[] nums) {
        if (nums == null || nums.length == 0)
            return -1;
        if (nums.length == 1)
            return nums[0];
        HashMap<Integer, Integer> hashMap = new HashMap<>();
        List<Integer> filter = new ArrayList<>();
        for (int num : nums) {
            if (!filter.contains(num)) {
                hashMap.put(num, hashMap.getOrDefault(num, 0) + 1);
                if (hashMap.get(num) > 1) {
                    hashMap.remove(num);
                    filter.add(num);
                }
            }
        }
        return (int) hashMap.keySet().toArray()[0];
    }

    public static void main(String[] args) {
        System.out.println(singleNumber(new int[]{1, 1, 1, 2, 3, 3, 3}));
    }
}
